#include "msp430x41x2.h"

char *LCD = LCDMEM;
//0,1,2,3,4,5,6,7,8,9 mask
//unsigned char digit[10]={0xeb,0x60,0xc7,0xe5,0x6c,0xad,0xaf,0xe0,0xef,0xed};// lcd=46041
unsigned char digit[10]={0xaf,0xa0,0xcb,0xe9,0xe4,0x6d,0x6f,0xa8,0xef,0xed}; //lcd=46
//idle,jiaoyan,ceshi flag mask
unsigned char mode_digit[3]={0x00,0x10,0x01};
//blank , 1=chaobiao, 2=zhengchang, 3=youliang
unsigned char result_digit[4]={0x00,0x01,0x41,0x49};
//batter voltage, high,normal,low
unsigned char voltage_digit[4]={0x00,0x49,0x41,0x01};

void LCD_intial(void)
{
  unsigned  int i,j;
  // unsigned char i;
  // Initialize LCD                           
  P5SEL |= BIT4+BIT5+BIT6+BIT7;               // Set COM pins for LCD
  LCDACTL =LCDON+LCDSTATIC+ LCDFREQ_128;     // STATIC LCD, ACLK/32  
  LCDAPCTL0 = 0xFF;                         // Segments 0-32
  LCDAPCTL1 = 0x00;                          // Segments 0-32
  LCDAVCTL0 = LCDCPEN;                      // charge pump enable
  LCDAVCTL1 = VLCD0;                      //   set to 2.60V



    for (i=0; i<16; i++)
    {
    LCD[i] = 0xff;
    } 
    delays(400);
    
    for (i=0; i<16; i++)
    {
    LCD[i] = 0;
    } 
    delays(400);
 
    for (i=0; i<16; i++)
    {
    LCD[i] = 0xff;
    } 
    delays(400);
    
    for (i=0; i<16; i++)
    {
    LCD[i] = 0;
    } 
    delays(400);

  
  
}

void Disp_Num(unsigned char num)
{
  switch(num)
  {
    case 1:
    {
      LCD[1]=0x01;
      LCD[2]=0x00;
      LCD[3]=0x00;
      LCD[4]=0x00;
      LCD[5]=0x00; 
      break;
    }
    case 2:
    {
      LCD[1]=0x11;
      LCD[2]=0x00;
      LCD[3]=0x00;
      LCD[4]=0x00;
      LCD[5]=0x00; 
      break;
    }    
    case 3:
    {
      LCD[1]=0x11;
      LCD[2]=0x01;
      LCD[3]=0x00;
      LCD[4]=0x00;
      LCD[5]=0x00; 
      break;
    }     
    case 4:
    {
      LCD[1]=0x11;
      LCD[2]=0x11;
      LCD[3]=0x00;
      LCD[4]=0x00;
      LCD[5]=0x00; 
      break;
    }     
    case 5:
    {
      LCD[1]=0x11;
      LCD[2]=0x11;
      LCD[3]=0x01;
      LCD[4]=0x00;
      LCD[5]=0x00; 
      break;
    }   
    case 6:
    {
      LCD[1]=0x11;
      LCD[2]=0x11;
      LCD[3]=0x11;
      LCD[4]=0x00;
      LCD[5]=0x00; 
      break;
    } 
    case 7:
    {
      LCD[1]=0x11;
      LCD[2]=0x11;
      LCD[3]=0x11;
      LCD[4]=0x01;
      LCD[5]=0x00; 
      break;
    } 
    case 8:
    {
      LCD[1]=0x11;
      LCD[2]=0x11;
      LCD[3]=0x11;
      LCD[4]=0x11;
      LCD[5]=0x00; 
      break;
    } 
    case 9:
    {
      LCD[1]=0x11;
      LCD[2]=0x11;
      LCD[3]=0x11;
      LCD[4]=0x11;
      LCD[5]=0x01; 
      break;
    }     
    case 10:
    {
      LCD[1]=0x11;
      LCD[2]=0x11;
      LCD[3]=0x11;
      LCD[4]=0x11;
      LCD[5]=0x11; 
      break;
    }      
    default:
      break;
    
  }//end of switch(num)

/*
unsigned char ten=0;
unsigned char one=0;

  ten=num/10;
  one=num%10;
  
  LCD[6]=digit[one];
  LCD[5]=digit[ten];
*/
}  


//idle,jiaoyan,ceshi flag mask
void Disp_Mode(unsigned char mod,unsigned char flash)
{
    if(flash==0)
    {LCD[0]=0;}
    if(flash==1)
    {LCD[0]=mode_digit[mod];}
}

//blank , 1=chaobiao, 2=zhengchang, 3=youliang
void Disp_Result(unsigned res)
{
//  LCD[4]=result_digit[res];  
  switch(res)
  {
    case 0:
      {
      LCD[6]=0x00;
      LCD[7]=0x10;
      break;
      }
    case 1:
      {
      LCD[6]=0x00;
      LCD[7]=0x11;
      break;
      }
    case 2:
      {
      LCD[6]=0x10;
      LCD[7]=0x10;
      break;
      }
    case 3:
      {
      LCD[6]=0x01;
      LCD[7]=0x10;
      break;
      } 
    default:
      break;
  }//end of swtich(res)
}
 
//batter voltage, high,normal,low
//Battery Voltage
//#define HIGH        1
//#define NORMAL      2
//#define LOW         3
void Disp_Batt(unsigned char vol) 
{
//  LCD[1]=voltage_digit[vol];
  switch(vol)
  {
    case 1://#define HIGH        1
      {
      LCD[7]=0x10;
      LCD[8]=0x11;
      break;
      }
    case 2://#define NORMAL      2
      {
      LCD[7]=0x10;
      LCD[8]=0x10;
      break;
      }
    case 3://#define LOW         3
      {
      LCD[7]=0x10;
      LCD[8]=0x00;
      break;
      } 
    default:
      break;
  }//end of swtich(res)
}

void Disp_Clear(void)
{
  LCD[0]=0;
  LCD[1]=0;
  LCD[2]=0;
  LCD[3]=0;
  LCD[4]=0;
  LCD[5]=0;
  LCD[6]=0;
  LCD[7]=0;
  LCD[8]=0;
  LCD[9]=0;
  LCD[10]=0;
  LCD[11]=0;
  LCD[12]=0;
}

void Disp_ALL(void)
{
  LCD[0]=0xff;
  LCD[1]=0xff;
  LCD[2]=0xff;
  LCD[3]=0xff;
  LCD[4]=0xff;
  LCD[5]=0xff;
  LCD[6]=0xff;
  LCD[7]=0xff;
  LCD[8]=0xff;
  LCD[9]=0xff;
  LCD[10]=0xff;
  LCD[11]=0xff;
  LCD[12]=0xff;

}
  

  








